package com.lry.basic.algorithm.common;

import org.omg.CORBA.INTERNAL;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/7/9
 */
public class MaxSubArraySum {
    public static void main(String[] args) {
        System.out.println(maxSubArraySum(new int[]{-1}));
    }

    /**
     * 最大连续子数组的和
     * @param arr
     * @return
     */
    public static int maxSubArraySum(int[] arr){
        if(null==arr||arr.length==0)return 0;
        int max = Integer.MIN_VALUE, real = 0;
        for(int i=0;i<arr.length;i++){
            real+=arr[i];
            if(real>max){
                max = real;
            }
            if(real<0)real = 0;
        }
        return max;
    }
}
